﻿<?php
	//require_once('quiz-model.php');
?>
<html>
<head>
<style>
	.wikitable{background: none repeat scroll 0 0 #F9F9F9;
    		border: 1px solid #AAAAAA;
    		border-collapse: collapse;
    		color: black;
   		margin: 1em 1em 1em 0;}
	.wikitable th, .wikitable td {
    		border: 1px solid #AAAAAA;
   		padding: 0.2em;}
	.wikitable tr:hover{
		background:yellow;
	}
	.wikitable th{background:blue}
	.wikitable tr td.name{cursor:pointer}
	
</style>
<script>
	function openEditBox(id, name, active){
		QUIZCATE.IdHold.value = id;
		QUIZCATE.NameHold.value = name;
		QUIZCATE.ActiveHold.checked = (active>0?'checked="checked"':'');
		QUIZCATE.EditBox.style.display = "block";
	}
	function closeEditBox(){
		QUIZCATE.EditBox.style.display = "none";		
	}
	
	function BodyOnLoad() {
		QUIZCATE = {
		IdHold: document.getElementById("id"),
		NameHold: document.getElementById("name"),
		ActiveHold: document.getElementById("active"),
		EditBox: document.getElementById("editBox")
		};
	}
	
</script>
</head>
<body>
	<a href="?act=quiz-list">Quản lý Quiz</a>
	<h2>Quản lý Quiz Category</h2>
	<form method="POST" action="?act=cate-add">
		<input type="text" name="name" style="width:300px" />
		<input type="submit" value="add" />
	</form>
	<table class="wikitable" style="text-align:center">
		<tr><th>id</th><th>name</th><th>active</th><th></th></tr>
		<?php			
			foreach ( $res as $row ) {
				echo "<tr><td>".$row['id']."</td><td class='name' title='sửa cate' onclick=\"openEditBox('".$row['id']."','".$row['name']."','".$row['active']."')\">".$row['name']."</td><td><input type='checkbox' ".($row['active']>0?"checked='checked'":"")."/></td><td><a href='?act=cate-delete&id=".$row['id']."'>delete</a></td></tr>";	
			}
		?>
	</table> 
	<div id="editBox" style="width:380px; height:150px; border:1px solid; display:none">
		<p style="text-decoration:underline; text-align:right; padding-right:9px;cursor:pointer" onclick="closeEditBox()">close</p>
		<form method="POST" action="?act=cate-edit" style="text-align:center">
			<input type="text" name="id" id="id" style="width:40px;text-align:center; background:white;border:none" READONLY/>
			<input type="text" name="name" id="name" style="width:300px" />
			<input type="checkbox" name="active" id="active" value="1" /><br /><br />
			<input type="submit" value="edit" />
		</form>
		<script>BodyOnLoad();</script>
	</div>
</body>
</html>